package com.base.cn.platform.os.controller.upload;

import com.base.cn.platform.os.common.WebBaseController;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.service.upload.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 前台文件上传Controller
 *
 * @author s.li
 * @create 2018-06-01-10:05
 */
@Controller
@RequestMapping("/web/uc/upload")
public class WebFileUploadController extends WebBaseController {

    @Autowired
    private FileUploadService fileUploadService;

    /**
     * 上传文件(只能上传图片)
     * @param file
     * @param fileParams
     * @return Map<String,Object>
     */
    @PostMapping(value = "/uploadImgFile",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @ResponseBody
    public Map<String,Object> uploadImgFile(@RequestPart(value = "file") MultipartFile file,
                                         @RequestParam(value = "fileParams",required = false) String fileParams) throws Exception{
        if(StringUtils.isNotEmpty(fileParams)){
            fileParams = fileParams.replaceAll("“","\"");
        }
        return fileUploadService.uploadFile(file,fileParams);
    }
}
